package lesson.c1;

import java.util.Arrays;

public class BasicInfo {
	
	public void basicType(){
		 // byte  
        System.out.println("基本类型：byte 二进制位数：" + Byte.SIZE);  
        System.out.println("包装类：java.lang.Byte");  
        System.out.println("最小值：Byte.MIN_VALUE=" + Byte.MIN_VALUE);  
        System.out.println("最大值：Byte.MAX_VALUE=" + Byte.MAX_VALUE);  
        System.out.println();  
  
        // short  
        System.out.println("基本类型：short 二进制位数：" + Short.SIZE);  
        System.out.println("包装类：java.lang.Short");  
        System.out.println("最小值：Short.MIN_VALUE=" + Short.MIN_VALUE);  
        System.out.println("最大值：Short.MAX_VALUE=" + Short.MAX_VALUE);  
        System.out.println();  
  
        // int  
        System.out.println("基本类型：int 二进制位数：" + Integer.SIZE);  
        System.out.println("包装类：java.lang.Integer");  
        System.out.println("最小值：Integer.MIN_VALUE=" + Integer.MIN_VALUE);  
        System.out.println("最大值：Integer.MAX_VALUE=" + Integer.MAX_VALUE);  
        System.out.println();  
  
        // long  
        System.out.println("基本类型：long 二进制位数：" + Long.SIZE);  
        System.out.println("包装类：java.lang.Long");  
        System.out.println("最小值：Long.MIN_VALUE=" + Long.MIN_VALUE);  
        System.out.println("最大值：Long.MAX_VALUE=" + Long.MAX_VALUE);  
        System.out.println();  
  
        // float  
        System.out.println("基本类型：float 二进制位数：" + Float.SIZE);  
        System.out.println("包装类：java.lang.Float");  
        System.out.println("最小值：Float.MIN_VALUE=" + Float.MIN_VALUE);  
        System.out.println("最大值：Float.MAX_VALUE=" + Float.MAX_VALUE);  
        System.out.println();  
  
        // double  
        System.out.println("基本类型：double 二进制位数：" + Double.SIZE);  
        System.out.println("包装类：java.lang.Double");  
        System.out.println("最小值：Double.MIN_VALUE=" + Double.MIN_VALUE);  
        System.out.println("最大值：Double.MAX_VALUE=" + Double.MAX_VALUE);  
        System.out.println();  
  
        // char  
        System.out.println("基本类型：char 二进制位数：" + Character.SIZE);  
        System.out.println("包装类：java.lang.Character");  
        // 以数值形式而不是字符形式将Character.MIN_VALUE输出到控制台  
        System.out.println("最小值：Character.MIN_VALUE="  
                + (int) Character.MIN_VALUE);  
        // 以数值形式而不是字符形式将Character.MAX_VALUE输出到控制台  
        System.out.println("最大值：Character.MAX_VALUE="  
                + (int) Character.MAX_VALUE);  
	}
	
	public void basicTypeTest(){
		int a = 10; //short long
		float b = 0.1f; // double
		char c = 'a';
		String d ="字符串"; //object
		System.out.printf("%d %f %c %s", a, b , c, d);
		
	}
	
	public void arrayInfo(){
		int[] a = new int[9];
		a[0] = 1;
		float[] b = new float[9];
		char[] c = {'i', 'c', 'u'};
		String[] d = new String[3];
		System.out.println(Arrays.toString(a));
		System.out.println(Arrays.toString(b));
		System.out.println(Arrays.toString(c));
		System.out.println(Arrays.toString(d));
	}

	public void calc1(){
		 //算术运算
		 int a = 10;
	     int b = 21;
	     int c = 25;
	     int d = 25;
	     System.out.println("a + b = " + (a + b) );
	     System.out.println("a - b = " + (a - b) );
	     System.out.println("a * b = " + (a * b) );
	     System.out.println("b / a = " + (b / a) );
	     System.out.println("b % a = " + (b % a) );
	     System.out.println("c % a = " + (c % a) );
	     System.out.println("a++   = " +  (a++) );
	     System.out.println("a--   = " +  (a--) );
	     // 查看  d++ 与 ++d 的不同
	     System.out.println("d++   = " +  (d++) );
	     System.out.println("++d   = " +  (++d) );
	    
	}
	
	public void calc2(){
		 //关系运算
	     int a = 10;
	     int b = 20;
	     System.out.println("a == b = " + (a == b) );
	     System.out.println("a != b = " + (a != b) );
	     System.out.println("a > b = " + (a > b) );
	     System.out.println("a < b = " + (a < b) );
	     System.out.println("b >= a = " + (b >= a) );
	     System.out.println("b <= a = " + (b <= a) );
	}
	
	public void calc3(){
		 //位运算符
		 int a = 60; /* 60 = 0011 1100 */ 
	     int b = 13; /* 13 = 0000 1101 */
	     int c = 0;
	     c = a & b;       /* 12 = 0000 1100 与*/ 
	     System.out.println("a & b = " + c );
	 
	     c = a | b;       /* 61 = 0011 1101 或*/
	     System.out.println("a | b = " + c );
	 
	     c = a ^ b;       /* 49 = 0011 0001 异或*/
	     System.out.println("a ^ b = " + c );
	 
	     c = ~a;          /*-61 = 1100 0011 反*/
	     System.out.println("~a = " + c );
	 
	     c = a << 2;     /* 240 = 1111 0000 */
	     System.out.println("a << 2 = " + c );
	 
	     c = a >> 2;     /* 15 = 1111 */
	     System.out.println("a >> 2  = " + c );
	  
	     c = a >>> 2;     /* 15 = 0000 1111 */
	     System.out.println("a >>> 2 = " + c );
	}
	
	public void calc4(){
		 //赋值运算
		 int a = 10;
	     int b = 20;
	     int c = 0;
	     c = a + b;
	     System.out.println("c = a + b = " + c );
	     c += a ;
	     System.out.println("c += a  = " + c );
	     c -= a ;
	     System.out.println("c -= a = " + c );
	     c *= a ;
	     System.out.println("c *= a = " + c );
	     a = 10;
	     c = 15;
	     c /= a ;
	     System.out.println("c /= a = " + c );
	     a = 10;
	     c = 15;
	     c %= a ;
	     System.out.println("c %= a  = " + c );
	     c <<= 2 ;
	     System.out.println("c <<= 2 = " + c );
	     c >>= 2 ;
	     System.out.println("c >>= 2 = " + c );
	     c >>= 2 ;
	     System.out.println("c >>= a = " + c );
	     c &= a ;
	     System.out.println("c &= 2  = " + c );
	     c ^= a ;
	     System.out.println("c ^= a   = " + c );
	     c |= a ;
	     System.out.println("c |= a   = " + c );
	}
	
	public void calc5(){
		//条件运算
		int a , b;
		a = 10;
		// 如果 a 等于 1 成立，则设置 b 为 20，否则为 30
		b = (a == 1) ? 20 : 30;
		System.out.println( "Value of b is : " +  b );
 
      // 如果 a 等于 10 成立，则设置 b 为 20，否则为 30
		b = (a == 10) ? a + 10 : a - 10;
		System.out.println( "Value of b is : " + b );
	}
	
	public void calc6(){
		//逻辑运算符
		boolean a = true;
	    boolean b = false;
	    System.out.println("a && b = " + (a&&b));
	    System.out.println("a || b = " + (a||b) );
	    System.out.println("!(a && b) = " + !(a && b));
	}
	
	public void ifelse(){
		int a = 100;
		int b = 1;
		if(b > 0){
			a -= 10;
		}else{
			a += 10;
		}
		System.out.println(a);
	}
	
	public void switchcase(){
		/* int , byte, char,  ++ String(JAVA SE7)*/
		int a;
		String c = "This is a String";
		switch(c){
		case "This is a String":
			a = 100;
			break;
		case "This is a String2":
			a = 200;
			break;
		default:
			a = 0;
			break;
		}
		System.out.println(a);
		
		char grade = 'C';
		 
		switch(grade)
		{
	     case 'A' :
	     	System.out.println("优秀"); 
	     	break;
		case 'B' :
		case 'C' :
			System.out.println("良好");
			break;
		case 'D' :
			System.out.println("及格");
		case 'F' :
			System.out.println("你需要再努力努力");
			break;
		default :
			System.out.println("未知等级");
		}
		System.out.println("你的等级是 " + grade);
	}
	
	public void loop1(){
		int a = 0;
		while( a > 0){
			System.out.println("Loop1 a = :" + a);
			--a;
		}
		System.out.println("Loop1 Final a = " + a);
	}
	
	public void loop2(){
		int a = 0;
		do{
			System.out.println("Loop2:" + a);
			--a;
		}while( a > 0);
		System.out.println("Loop2 Final a = " + a);
	}
	
	public void loop3(){
		int[] a = {1,2,3,4,5,6,7,8,9,10};
		int sum = 0;
		for (int i = 0; i < a.length ; i ++ ){
			sum += a[i];
		}
		System.out.println("Loop3 sum = " + sum);
	}
	
	public void loop4(){
		int[] a = {1,2,3,4,5,6,7,8,9,10};
		int sum = 0;
		for (int item: a ){
			sum += item;
		}
		System.out.println("Loop4 sum = " + sum);
	}
	
	public void loop5(){
		String[] objs = {"This", "is", "a", "test", "function"};
		String sum = "";
		for (String item: objs ){
			sum += " " + item;
		}
		System.out.println("Loop4 sum = " + sum);
	}
	
	public static void main(String[] args) {
		BasicInfo bt = new BasicInfo();
		bt.basicType();
	}
}


